package com.leiqichao.backend.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.leiqichao.backend.entity.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;

public interface CategoryMapper extends BaseMapper<Category> {

    /**
     * 查询子分类列表（非树形）
     * @param parentId 父分类ID
     */
    @Select("SELECT * FROM categories WHERE parent_id = #{parentId} AND is_deleted = 0 ORDER BY `order` ASC")
    List<Category> selectChildren(Long parentId);

    /**
     * 查询全部分类树
     */
    @Select("SELECT * FROM categories WHERE is_deleted = 0 ORDER BY `order` ASC")
    List<Category> selectCategoryTree();

    /**
     * 逻辑删除（覆盖MyBatis-Plus默认的物理删除）
     * @param id 分类ID
     */
    @Delete("UPDATE categories SET is_deleted = 1 WHERE id = #{id}")
    int deleteById(@Param("id") Long id);
}